package com.rich.dmr.databases;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class DataBaseConnection extends SQLiteOpenHelper {
	private static String TAG = "rich---MyDatabaseHelper";
	private static final String db_name="dmr_app.db";
	private static final int version=1;
	private Context mContext;
	public static final String CREATE_FREQUENCY = "create table frequency (_id integer primary key autoincrement,"
			+ "channel integer,"
			+ "tx_frequency integer,"
			+ "rx_frequency integer);";
	public static final String CREATE_TX_FREQUENCY = "create table tx_frequency (_id integer primary key autoincrement,"
			+ "channel integer,"
			+ "frequency integer);";
	public static final String CREATE_RX_FREQUENCY = "create table rx_frequency (_id integer primary key autoincrement,"
			+ "channel integer,"
			+ "frequency integer);";
	public static final String CREATE_CHANNEL_DB = "create table channel_list (_id integer primary key autoincrement,"
			+ "channel_name varchar,"
			+ "tx_fre integer,"
			+ "rx_fre integer);";
	public static final String CREATE_RX_LIST_DB = "create table rx_list (_id integer primary key autoincrement,"
			+ "rx_name varchar,"
			+ "rx_list varchar);";
	
	public static final String CREATE_CONTACT_DB = "create table dmr_contact ("
		+ "_id integer primary key autoincrement,"
		+ "name varchar,"
		+ "phone integer,"
		+ "call_type integer,"
		+ "color integer);";

	public DataBaseConnection(Context context) {
		super(context, db_name, null, version);
		mContext = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		try {
			db.execSQL(CREATE_FREQUENCY);
			db.execSQL(CREATE_TX_FREQUENCY);
			db.execSQL(CREATE_RX_FREQUENCY);
			db.execSQL(CREATE_CHANNEL_DB);
			db.execSQL(CREATE_RX_LIST_DB);
			db.execSQL(CREATE_CONTACT_DB);
			Log.d(TAG,"db create success");

		} catch (SQLException e) {
			e.printStackTrace();
			Log.d(TAG,"db create fail");
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists frequency");
		db.execSQL("drop table if exists tx_frequency");
		db.execSQL("drop table if exists rx_frequency");
		db.execSQL("drop table if exists channel_list");
		db.execSQL("drop table if exists rx_list");
		db.execSQL("drop table if exists dmr_contact");
		onCreate(db);
		Log.d(TAG, "db delete success");
	}
}
